function FinderServiceBox(){    	
    this.itIdAlias = new InputText("");
    this.itIdAlias.setLabel("cod.");
    this.itIdAlias.setIcon("icon-search");
    this.itIdAlias.htmlX.css({"float":"left","margin-right":"4px"});
    this.btEscolher = new js.underas.controller.Button("Selecionar");
    this.itDescAlias = new InputText("");
    this.itDescAlias.setLabel("descricao:");
    this.itDescAlias.setIcon("icon-search");
    this.itDescAlias.setSize(3);
    this.itDescAlias.htmlX.css({"float":"right"});
    this.caixaH = new HBox();
    this.dtgItensService = new DataGrid();        
    this.selectedService = "";    
    this.uidDataFind = ""; 
        
    this.itIdAlias.htmlX.addClass("itIdAlias");  
    this.itDescAlias.htmlX.addClass("itDescAlias");
	    	
    this.dtgItensService.itemChange=this.mudarValores;        
           
    TitleWindow.apply(this,["pesquisa"]);
    this.htmlX.addClass("FinderServiceBox").css("z-index",6960);
    this.htmlX[0]["dta"] = this;
	
    this.btEscolher.htmlX.click($.proxy(this.selecionarItem,this));
	this.itDescAlias.htmlX.keyup($.proxy(this.filtrarItem,this));
	
    this.append(this.itIdAlias);
    this.append(this.itDescAlias);
    this.append(this.dtgItensService);
    this.append(this.btEscolher);
}
	
FinderServiceBox.prototype.setService = function(service){
    var tmpService = ServicesSingleTone.getServiceByDesc(service);
    this.selectedService = service;
    this.dtgItensService.setColumns([{"label":"codigo","column":tmpService.idAlias,"width":"50px"},{"label":"descricao","column":tmpService.descAlias,"width":"150px"}]);
    this.dtgItensService.setDataProvider(tmpService.dataProvider);    
    this.dtgItensService;
    this.dtgItensService.setHeight(120);
};

FinderServiceBox.prototype.setIdDataFind = function(idDataFind){
   this.uidDataFind = idDataFind;
};

FinderServiceBox.prototype.filtrarItem = function(){
	var tmpService = ServicesSingleTone.getServiceByDesc(fsb.selectedService);
	var valor = this.itDescAlias.getValue();
	var campo = tmpService.descAlias;
	valor = valor.toUpperCase();
	var arrtmp = $.extend(true, [], tmpService.dataProvider);
	this.dtgItensService.setDataProvider(arrtmp.filter( function(element, index, array) {
		return (element[campo].toUpperCase().indexOf(valor)>-1);
	}));	   
	this.dtgItensService;
}; 
FinderServiceBox.prototype.mudarValores = function(){
    var tmpService = ServicesSingleTone.getServiceByDesc(fsb.selectedService);
    var itemI = fsb.dtgItensService.getSelectedItem();
    //alert(produtoI.idProduto);
    fsb.itIdAlias.setValue(itemI[tmpService.idAlias]);
    fsb.itDescAlias.setValue(itemI[tmpService.descAlias]);
};
FinderServiceBox.prototype.selecionarItem = function(){
    $("#"+this.uidDataFind)[0]["dta"].setValue(fsb.itIdAlias.getValue());
    this.show(false,true);
};

var fsb = null;	
 $(function(){
	fsb = new FinderServiceBox();
	$("body").append(fsb.htmlX);
});
